package com.xebest.web.controller.purch;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.xebest.api.util.OpertorLogUtil;
import com.xebest.common.base.controller.BASEMessage;
import com.xebest.common.base.controller.BaseController;
import com.xebest.common.base.controller.BaseResponse;
import com.xebest.common.enums.erp.purch.VenAddTypeEnum;
import com.xebest.common.enums.erp.purch.VenPurchCheckEnum;
import com.xebest.common.enums.erp.purch.VenPurchStatusEnum;
import com.xebest.common.enums.erp.purch.VenPurchTypeEnum;
import com.xebest.common.enums.logtype.ErpLogTypeEnum;
import com.xebest.common.util.RequestUtil;
import com.xebest.config.ParamConfig;
import com.xebest.constant.XeConstans;
import com.xebest.util.SysSetBeanUtils;
import com.xebest.util.seq.PurchSeqUtil;
import com.xebest.web.controller.order.XeVenOrderController;
import com.xebest.web.form.XeVenPurchForm;
import com.xebest.web.form.XeVenPurchProductForm;
import com.xebest.web.model.base.XePageInfo;
import com.xebest.web.service.XeVenPurchService;
import com.xebest.web.view.ErpUserInfo;
import com.xebest.web.view.XeVenPurchProductView;
import com.xebest.web.view.XeVenPurchView;
import com.xebest.web.view.XeVenSumPurchView;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 采购相关
 *
 * @author 李书峰
 */
@RestController
@RequestMapping("purch")
public class XeVenPurchController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(XeVenOrderController.class);//日志记录类

    @Autowired
    private XeVenPurchService xeVenPurchService;//采购相关业务操作
    @Autowired
    private ParamConfig paramConfig;//获取公共配置信息
    private String picDir = XeConstans.ERP_PRO_PIC_DIR;//图片中缀

    /**
     * 查询采购单列表
     *
     * @author 李书峰
     */
    @RequestMapping("queryPurchList")
    @ResponseBody
    public BaseResponse queryPurchList(@RequestBody XeVenPurchForm form) {
        log.info("--------------查询采购单列表 start-------------------");
        // 1、验证参数
        // 2、拼装参数
        if (null == form) {
            form = new XeVenPurchForm();
        }
        XePageInfo<XeVenPurchView> xePageInfo;
        PageHelper.startPage(form.getPageNum(), form.getPageSize(), true);
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());

        try {
            // 3、输出结果
            List<XeVenPurchView> purchList = xeVenPurchService.queryPurchList(form);
            //log.info("查询采购单列表结果：",JSONArray.toJSON(purchList).toString());
            xePageInfo = new XePageInfo<XeVenPurchView>(purchList);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("purchList", purchList);
            map.put("xePageInfo", xePageInfo);
            return sendAjaxOK(map);
        } catch (Exception e) {
            log.error("查询采购单列表queryPurchList()异常：{}", e);
            return sendAjaxError("查询采购单异常");
        } finally {
            log.info("--------------查询采购单列表end-------------------");
        }
    }


    /**
     * 采购单详情
     *
     * @author 李书峰
     */
    @RequestMapping("queryPurchDetail")
    @ResponseBody
    public BaseResponse queryPurchDetail(@RequestBody XeVenPurchForm form) {
        log.info("--------------查询采购详情start-------------------");
        Map<String, Object> resultMap = new HashMap<String, Object>();
        // 1、验证参数
        boolean parError = true;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())
                && null != form.getVersion()) {
            parError = false;
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        try {
            // 3、输出结果
            XeVenPurchView purch = xeVenPurchService.queryPurchDetail(form);
            if (null == purch || StringUtils.isBlank(purch.getPurchOrder())) {
                resultMap.put("code", "1110");
                resultMap.put("msg", "单据状态已变更，不能进行该操作");
            } else {
                resultMap.put("purch", purch);
                String picServer = paramConfig.getImgUrl();//图片服务器地址
                resultMap.put("picServer", picServer);
                resultMap.put("picDir", picDir);
            }
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("查询采购详情queryPurchDetail()异常：{}", e);
            return sendAjaxError("查询采购详情异常");
        } finally {
            log.info("--------------查询采购详情end-------------------");
        }

    }

    /**
     * 采购单商品列表
     *
     * @author 李书峰
     */
    @RequestMapping("queryPurchProducts")
    @ResponseBody
    public BaseResponse queryPurchProducts(@RequestBody XeVenPurchForm form) {
        log.info("--------------查询采购商品列表start-------------------");
        // 1、验证参数
        boolean parError = true;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())) {
            parError = false;
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {
            // 3、输出结果
            List<XeVenPurchProductView> productList = xeVenPurchService.queryPurchProducts(form);
            //log.info("查询采购商品列表结果：",JSONArray.toJSON(productList).toString());
            resultMap.put("productList", productList);
            String picServer = paramConfig.getImgUrl();//图片服务器地址
            resultMap.put("picServer", picServer);
            resultMap.put("picDir", picDir);
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("查询采购商品列表queryPurchProducts()异常：{}", e);
            return sendAjaxError("查询采购商品列表异常");
        } finally {
            log.info("--------------查询采购商品列表end-------------------");
        }
    }

    /**
     * 采购单收货入库详情
     *
     * @author 李书峰
     */
    @RequestMapping("queryReceiptDetail")
    @ResponseBody
    public BaseResponse queryReceiptDetail(@RequestBody XeVenPurchForm form) {
        log.info("--------------查询采购商品列表start-------------------");
        // 1、验证参数
        boolean parError = true;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())) {
            parError = false;
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setModifyUser(userInfo.getLoginName());
        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {
            // 3、输出结果
            resultMap = xeVenPurchService.queryReceiptDetail(form);
            String picServer = paramConfig.getImgUrl();//图片服务器地址
            resultMap.put("picServer", picServer);
            resultMap.put("picDir", picDir);
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("查询采购商品列表queryPurchProducts()异常：{}", e);
            return sendAjaxError("查询采购商品列表异常");
        } finally {
            log.info("--------------查询采购商品列表end-------------------");
        }
    }

    /**
     * 新增采购单
     *
     * @author 李书峰
     */
    @RequestMapping("insertPurch")
    @ResponseBody
    public BaseResponse insertPurch(@RequestBody @Validated XeVenPurchForm form, BindingResult bindingResult) {
        log.info("--------------新增采购单start-------------------");
        // 1、验证参数
        boolean parError = true;
        if (null != form
                && null != form.getPurchProductList()
                ) {
            parError = false;
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        if (bindingResult.hasErrors()) {
            return sendAjaxError(BASEMessage.PARAM_ERROR, bindingResult.getFieldError().getDefaultMessage());
        }
        if (null != form.getCheckStatus()
                && null != form.getPurchStatus()
                && !form.getCheckStatus().equals(form.getPurchStatus())) {
            return sendAjaxError("审核状态和采购单状态不匹配！");
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setModifyUser(userInfo.getLoginName());
        form.setPurchOrder(PurchSeqUtil.seqUtils.createPurchOrder());
        form.setAddType(VenAddTypeEnum.MANUAL.getValue());
        String operateContent = "新增采购单，单号为：" + form.getPurchOrder();
        try {
            // 3、输出结果
            int result = xeVenPurchService.insertPurchOrder(form);
            if (result > 0) {
                insertMqLog(ErpLogTypeEnum.erpPurchInsertPurch.getValue(), form.getPurchOrder(), operateContent);
                return sendAjaxOK();
            } else {
                return sendAjaxError(BASEMessage.ERROR);
            }
        } catch (Exception e) {
            log.error("新增采购单insertPurch()异常：{}", e);
            return sendAjaxError("新增采购单异常");
        } finally {
            log.info("--------------新增采购单end-------------------");
        }
    }

    /**
     * 编辑采购单
     *
     * @author 李书峰
     */
    @RequestMapping("updatePurch")
    @ResponseBody
    public BaseResponse updatePurch(@RequestBody XeVenPurchForm form) {
        log.info("--------------编辑采购单start-------------------");
        // 1、验证参数
        boolean parError = true;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())
                && null != form.getVersion()
                && null != form.getCheckStatus()
                && null != form.getPurchStatus()
                && null != form.getCheckStatusPre()
                && null != form.getPurchStatusPre()
                && (VenPurchCheckEnum.WAIT_SUBMIT.getValue().equals(form.getCheckStatusPre())
                || VenPurchCheckEnum.XIAN_REJECT.getValue().equals(form.getCheckStatusPre())
                || VenPurchCheckEnum.FINANCE_REJECT.getValue().equals(form.getCheckStatusPre())
                || VenPurchCheckEnum.PURCH_REJECT.getValue().equals(form.getCheckStatusPre()))
                && (VenPurchCheckEnum.WAIT_SUBMIT.getValue().equals(form.getCheckStatus())
                || VenPurchCheckEnum.PURCH_CHECK.getValue().equals(form.getCheckStatus())
                || VenPurchCheckEnum.FINANCE_REJECT.getValue().equals(form.getCheckStatus())
                || VenPurchCheckEnum.XIAN_REJECT.getValue().equals(form.getCheckStatus())
                || VenPurchCheckEnum.PURCH_REJECT.getValue().equals(form.getCheckStatus()))
                && (VenPurchStatusEnum.WAIT_SUBMIT.getValue().equals(form.getPurchStatusPre())
                || VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre()))
                && (VenPurchStatusEnum.WAIT_SUBMIT.getValue().equals(form.getPurchStatus())
                || VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus()))
                ) {
            parError = false;
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setModifyUser(userInfo.getLoginName());
        String operateContent = "编辑采购单，单号为：" + form.getPurchOrder() + "," + JSON.toJSONString(form);
        try {
            // 3、输出结果
            int result = xeVenPurchService.updatePurchOrder(form);
            //log.info("编辑采购单结果：",result);
            if (result > 0) {
                insertMqLog(ErpLogTypeEnum.erpPurchUpdatePurch.getValue(), form.getPurchOrder(), operateContent);
                return sendAjaxOK();
            } else {
                return sendAjaxOK("该采购单不存在，或已发生变更，请刷新页面重试！");
            }
        } catch (Exception e) {
            log.error("编辑采购单updatePurch()异常：{}", e);
            return sendAjaxError("编辑采购单异常");
        } finally {
            log.info("--------------编辑采购单end-------------------");
        }
    }

    /**
     * 删除采购单
     *
     * @author 李书峰
     */
    @RequestMapping("delPurch")
    @ResponseBody
    public BaseResponse delPurch(@RequestBody XeVenPurchForm form) {
        log.info("--------------删除采购单start-------------------");
        // 1、验证参数
        boolean parError = true;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())
                && null != form.getPurchStatusPre()
                && VenPurchStatusEnum.WAIT_SUBMIT.getValue().equals(form.getPurchStatusPre())
                && null != form.getCheckStatusPre()
                && VenPurchCheckEnum.WAIT_SUBMIT.getValue().equals(form.getCheckStatusPre())
                && null != form.getPurchType()
                && VenPurchTypeEnum.LARGE_BUY.getValue().equals(form.getPurchType())
                && null != form.getVersion()) {
            parError = false;
        }
        if (parError) {
            if (null != form.getPurchStatusPre()
                    && VenPurchStatusEnum.WAIT_SUBMIT.getValue().equals(form.getPurchStatusPre())
                    && null != form.getCheckStatusPre()
                    && VenPurchCheckEnum.WAIT_SUBMIT.getValue().equals(form.getCheckStatusPre())) {
                return sendAjaxError("只有待提交采购单可以被删除");
            } else if (null != form.getPurchType()
                    && VenPurchTypeEnum.LARGE_BUY.getValue().equals(form.getPurchType())) {
                return sendAjaxError("只有集采的采购单可以被删除");
            } else {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setModifyUser(userInfo.getLoginName());
        String operateContent = "删除采购单，单号为：" + form.getPurchOrder();
        try {
            // 3、输出结果
            List<XeVenPurchForm> xeVenPurchFormList = new ArrayList<XeVenPurchForm>();
            xeVenPurchFormList.add(form);
            Map<String, Object> reult = xeVenPurchService.deletePurchOrder(xeVenPurchFormList);
            int resultSize = Integer.valueOf(reult.get("successSize").toString());
            if (resultSize > 0) {
                insertMqLog(ErpLogTypeEnum.erpPurchDelPurch.getValue(), form.getPurchOrder(), operateContent);
                return sendAjaxOK();
            } else {
                return sendAjaxOK("该采购单不存在，或已发生变更，请刷新页面重试！");
            }
        } catch (Exception e) {
            log.error("删除采购单delPurch()异常：{}", e);
            return sendAjaxError("删除采购单异常");
        } finally {
            log.info("--------------删除采购单end-------------------");
        }
    }

    /**
     * 采购审核采购单
     *
     * @author 李书峰
     */
    @RequestMapping("purchCheck")
    @ResponseBody
    public BaseResponse purchCheck(@RequestBody XeVenPurchForm form) {
        log.info("--------------采购审核采购单start-------------------");
        // 1、验证参数
        boolean parError = true;
        Map<String, Object> resultData = null;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())
                && null != form.getCheckStatus()
                && null != form.getPurchStatus()
                && null != form.getCheckStatusPre()
                && null != form.getPurchStatusPre()
                && (VenPurchCheckEnum.PURCH_CHECK.getValue().equals(form.getCheckStatusPre())
                || VenPurchCheckEnum.FINANCE_REJECT.getValue().equals(form.getCheckStatusPre())
                || VenPurchCheckEnum.XIAN_REJECT.getValue().equals(form.getCheckStatusPre())
                || VenPurchCheckEnum.PURCH_REJECT.getValue().equals(form.getCheckStatusPre()))
                && VenPurchCheckEnum.XIAN_CHECK.getValue().equals(form.getCheckStatus())
                && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())
                && null != form.getVersion()) {
            parError = false;
        }
        if (parError) {
            if (!VenPurchCheckEnum.XIAN_CHECK.getValue().equals(form.getCheckStatusPre())
                    || !VenPurchCheckEnum.XIAN_REJECT.getValue().equals(form.getCheckStatus())
                    || !VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                    || !VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())) {
                resultData = new HashMap<String, Object>();
                resultData.put("code", "1110");
                resultData.put("msg", "单据状态已变更，不能进行该操作");
                return sendAjaxOK(resultData);
            } else {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setModifyUser(userInfo.getLoginName());
        try {
            // 3、输出结果
            List<XeVenPurchForm> xeVenPurchFormList = new ArrayList<XeVenPurchForm>();
            xeVenPurchFormList.add(form);
            String operateContent = "采购部审核通过采购单，单号为：" + form.getPurchOrder();
            Map<String, Object> reult = xeVenPurchService.purchCheck(xeVenPurchFormList);
            int resultSize = Integer.valueOf(reult.get("successSize").toString());
            if (resultSize > 0) {
                insertMqLog(ErpLogTypeEnum.erpPurchPurchCheck.getValue(), form.getPurchOrder(), operateContent);
                return sendAjaxOK();
            } else {
                return sendAjaxOK("该采购单不存在，或已发生变更，请刷新页面重试！");
            }
        } catch (Exception e) {
            log.error("采购审核采购单purchCheck()异常：{}", e);
            return sendAjaxError("采购审核采购单异常");
        } finally {
            log.info("--------------采购审核采购单end-------------------");
        }
    }

    /**
     * 采购部驳回采购单
     *
     * @author 李书峰
     */
    @RequestMapping("purchReject")
    @ResponseBody
    public BaseResponse purchReject(@RequestBody XeVenPurchForm form) {
        log.info("--------------采购审核采购单start-------------------");
        // 1、验证参数
        boolean parError = true;
        Map<String, Object> resultData = null;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())
                && StringUtils.isNotBlank(form.getPurchExamineRemark())
                && null != form.getCheckStatus()
                && null != form.getPurchStatus()
                && null != form.getCheckStatusPre()
                && null != form.getPurchStatusPre()
                && VenPurchCheckEnum.PURCH_CHECK.getValue().equals(form.getCheckStatusPre())
                && VenPurchCheckEnum.PURCH_REJECT.getValue().equals(form.getCheckStatus())
                && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())
                && null != form.getVersion()) {
            parError = false;
        }
        if (parError) {
            if (!VenPurchCheckEnum.XIAN_CHECK.getValue().equals(form.getCheckStatusPre())
                    || !VenPurchCheckEnum.XIAN_REJECT.getValue().equals(form.getCheckStatus())
                    || !VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                    || !VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())) {
                resultData = new HashMap<String, Object>();
                resultData.put("code", "1110");
                resultData.put("msg", "单据状态已变更，不能进行该操作");
                return sendAjaxOK(resultData);
            } else {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setModifyUser(userInfo.getLoginName());
        try {
            // 3、输出结果
            List<XeVenPurchForm> xeVenPurchFormList = new ArrayList<XeVenPurchForm>();
            xeVenPurchFormList.add(form);
            String operateContent = "采购部审核驳回采购单，单号为：" + form.getPurchOrder() + "，驳回原因：" + form.getPurchExamineRemark();
            Map<String, Object> reult = xeVenPurchService.purchCheck(xeVenPurchFormList);
            int resultSize = Integer.valueOf(reult.get("successSize").toString());
            if (resultSize > 0) {
                insertMqLog(ErpLogTypeEnum.erpPurchPurchReject.getValue(), form.getPurchOrder(), operateContent);
                return sendAjaxOK();
            } else {
                return sendAjaxOK("该采购单不存在，或已发生变更，请刷新页面重试！");
            }
        } catch (Exception e) {
            log.error("采购审核采购单purchCheck()异常：{}", e);
            return sendAjaxError("采购审核采购单异常");
        } finally {
            log.info("--------------采购审核采购单end-------------------");
        }
    }

    /**
     * 财务部审核采购单
     *
     * @author 李书峰
     */
    @RequestMapping("financeCheck")
    @ResponseBody
    public BaseResponse financeCheck(@RequestBody XeVenPurchForm form) {
        log.info("-------financeCheck-------财务审核采购单start-------------------");
        // 1、验证参数
        boolean parError = true;
        Map<String, Object> resultData = null;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())
                && null != form.getCheckStatus()
                && null != form.getPurchStatus()
                && null != form.getCheckStatusPre()
                && null != form.getPurchStatusPre()
                && VenPurchCheckEnum.FINANCE_CHECK.getValue().equals(form.getCheckStatusPre())
                && VenPurchCheckEnum.CHECKED.getValue().equals(form.getCheckStatus())
                && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                && VenPurchStatusEnum.PURCHING.getValue().equals(form.getPurchStatus())
                && null != form.getVersion()) {
            parError = false;
        }
        if (parError) {
            if (!VenPurchCheckEnum.XIAN_CHECK.getValue().equals(form.getCheckStatusPre())
                    || !VenPurchCheckEnum.XIAN_REJECT.getValue().equals(form.getCheckStatus())
                    || !VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                    || !VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())) {
                resultData = new HashMap<String, Object>();
                resultData.put("code", "1110");
                resultData.put("msg", "单据状态已变更，不能进行该操作");
                return sendAjaxOK(resultData);
            } else {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setModifyUser(userInfo.getLoginName());
        try {
            // 3、输出结果
            List<XeVenPurchForm> xeVenPurchFormList = new ArrayList<XeVenPurchForm>();
            xeVenPurchFormList.add(form);
            String operateContent = "财务部审核通过采购单，单号为：" + form.getPurchOrder();
            Map<String, Object> reult = xeVenPurchService.financeCheck(xeVenPurchFormList);
            int resultSize = Integer.valueOf(reult.get("successSize").toString());
            if (resultSize > 0) {
                insertMqLog(ErpLogTypeEnum.erpPurchFinanceCheck.getValue(), form.getPurchOrder(), operateContent);
                return sendAjaxOK();
            } else {
                return sendAjaxOK("该采购单不存在，或已发生变更，请刷新页面重试！");
            }
        } catch (Exception e) {
            log.error("财务审核采购单financeCheck()异常：{}", e);
            return sendAjaxError("财务审核采购单异常");
        } finally {
            log.info("--------------财务审核采购单end-------------------");
        }
    }

    /**
     * 财务部驳回采购单
     *
     * @author 李书峰
     */
    @RequestMapping("financeReject")
    @ResponseBody
    public BaseResponse financeReject(@RequestBody XeVenPurchForm form) {
        log.info("--------------财务审核采购单start-------------------");
        // 1、验证参数
        boolean parError = true;
        Map<String, Object> resultData = null;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())
                && StringUtils.isNotBlank(form.getFinanceExamineRemark())
                && null != form.getCheckStatus()
                && null != form.getPurchStatus()
                && null != form.getCheckStatusPre()
                && null != form.getPurchStatusPre()
                && VenPurchCheckEnum.FINANCE_CHECK.getValue().equals(form.getCheckStatusPre())
                && VenPurchCheckEnum.FINANCE_REJECT.getValue().equals(form.getCheckStatus())
                && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())
                && null != form.getVersion()) {
            parError = false;
        }
        if (parError) {
            if (!VenPurchCheckEnum.XIAN_CHECK.getValue().equals(form.getCheckStatusPre())
                    || !VenPurchCheckEnum.XIAN_REJECT.getValue().equals(form.getCheckStatus())
                    || !VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                    || !VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())) {
                resultData = new HashMap<String, Object>();
                resultData.put("code", "1110");
                resultData.put("msg", "单据状态已变更，不能进行该操作");
                return sendAjaxOK(resultData);
            } else {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setModifyUser(userInfo.getLoginName());
        try {
            // 3、输出结果
            List<XeVenPurchForm> xeVenPurchFormList = new ArrayList<XeVenPurchForm>();
            xeVenPurchFormList.add(form);
            String operateContent = "财务部审核驳回采购单，单号为：" + form.getPurchOrder() + "，驳回原因：" + form.getFinanceExamineRemark();
            Map<String, Object> reult = xeVenPurchService.financeCheck(xeVenPurchFormList);
            int resultSize = Integer.valueOf(reult.get("successSize").toString());
            if (resultSize > 0) {
                insertMqLog(ErpLogTypeEnum.erpPurchFinanceReject.getValue(), form.getPurchOrder(), operateContent);
                return sendAjaxOK();
            } else {
                return sendAjaxOK("该采购单不存在，或已发生变更，请刷新页面重试！");
            }
        } catch (Exception e) {
            log.error("财务审核采购单financeCheck()异常：{}", e);
            return sendAjaxError("财务审核采购单异常");
        } finally {
            log.info("--------------财务审核采购单end-------------------");
        }
    }

    /**
     * 确认完成采购单
     *
     * @author 李书峰
     */
    @RequestMapping("finishPurch")
    @ResponseBody
    public BaseResponse finishPurch(@RequestBody XeVenPurchForm form) {
        log.info("--------------确认完成采购单start-------------------");
        // 1、验证参数
        boolean parError = true;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())
                && null != form.getPurchStatusPre()
                && VenPurchStatusEnum.PURCHING.getValue().equals(form.getPurchStatusPre())
                && null != form.getPurchType()
                && !VenPurchTypeEnum.RETAIL_BUY.getValue().equals(form.getPurchType())
                && null != form.getAddType()
                && VenAddTypeEnum.MANUAL.getValue().equals(form.getAddType())
                && null != form.getVersion()) {
            parError = false;
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setModifyUser(userInfo.getLoginName());
        String operateContent = "异常完成采购单，单号为：" + form.getPurchOrder();
        try {
            // 3、输出结果
            if (VenPurchTypeEnum.ALLOT_BUY.getValue().equals(form.getPurchType())
                    && VenAddTypeEnum.MANUAL.getValue().equals(form.getAddType())) {
                //整柜手动需要判断
                form = xeVenPurchService.sendGoodsIsFinish(form);
            } else {
                form.setPurchStatus(VenPurchStatusEnum.ABNORMAL_COMPLETE.getValue());
            }
            if (null != form.getDelFlag() && new Integer(5).equals(form.getDelFlag())) {
                return sendAjaxOK("当前还有关联未发货订单，请先进性发货！");
            }
            int result = xeVenPurchService.finishPurchOrder(form);
            //log.info("确认完成采购结果：",result);
            if (result > 0) {
                insertMqLog(ErpLogTypeEnum.erpPurchFinishPurch.getValue(), form.getPurchOrder(), operateContent);
                return sendAjaxOK();
            } else {
                return sendAjaxOK("该采购单不存在，或已发生变更，请刷新页面重试！");
            }
        } catch (Exception e) {
            log.error("确认完成采购单finishPurch()异常：{}", e);
            return sendAjaxError("确认完成采购单异常");
        } finally {
            log.info("--------------确认完成采购单end-------------------");
        }
    }

    /**
     * 采购收货入库列表
     *
     * @author 李书峰
     */
    @RequestMapping("queryReceiptList")
    @ResponseBody
    public BaseResponse queryReceiptList(@RequestBody XeVenPurchForm form) {
        // 1、验证参数
        // 2、拼装参数
        if (null == form) {
            form = new XeVenPurchForm();
        }
        XePageInfo<XeVenPurchView> xePageInfo;
        PageHelper.startPage(form.getPageNum(), form.getPageSize(), true);
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setCheckStatus(VenPurchCheckEnum.CHECKED.getValue());
        form.setPurchStatus(VenPurchStatusEnum.PURCHING.getValue());
        form.setPurchType(VenPurchTypeEnum.LARGE_BUY.getValue());
        try {
            // 3、输出结果
            List<XeVenPurchView> purchList = xeVenPurchService.queryPurchList(form);
            //log.info("查询采购单列表结果：",JSONArray.toJSON(purchList).toString());
            xePageInfo = new XePageInfo<XeVenPurchView>(purchList);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("purchList", purchList);
            map.put("xePageInfo", xePageInfo);
            return sendAjaxOK(map);
        } catch (Exception e) {
            log.error("查询采购单收货入库列表queryPurchList()异常：{}", e);
            return sendAjaxError("查询采购收货入库异常");
        } finally {
        }
    }

    /**
     * 财务审核采购单列表
     *
     * @author 李书峰
     */
    @RequestMapping("queryFinanceCheckList")
    @ResponseBody
    public BaseResponse queryFinanceCheckList(@RequestBody XeVenPurchForm form) {
        // 1、验证参数
        // 2、拼装参数
        if (null == form) {
            form = new XeVenPurchForm();
        }
        XePageInfo<XeVenPurchView> xePageInfo;
        PageHelper.startPage(form.getPageNum(), form.getPageSize(), true);
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setIsCheckList(1);
//		form.setPurchStatus(VenPurchStatusEnum.CHECKING.getValue());
        form.setFinCheckListFlag(111);
        try {
            // 3、输出结果
            List<XeVenPurchView> purchList = xeVenPurchService.queryPurchList(form);
            //log.info("查询采购单列表结果：",JSONArray.toJSON(purchList).toString());
            xePageInfo = new XePageInfo<XeVenPurchView>(purchList);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("purchList", purchList);
            map.put("xePageInfo", xePageInfo);
            return sendAjaxOK(map);
        } catch (Exception e) {
            log.error("查询财务审核采购单列表queryPurchList()异常：{}", e);
            return sendAjaxError("查询财务审核采购单列表异常");
        } finally {
        }
    }

    /**
     * 鲜咨达审核采购单列表
     *
     * @author 李书峰
     */
    @RequestMapping("queryXianCheckList")
    @ResponseBody
    public BaseResponse queryXianCheckList(@RequestBody XeVenPurchForm form) {
        // 1、验证参数
        // 2、拼装参数
        if (null == form) {
            form = new XeVenPurchForm();
        }
        XePageInfo<XeVenPurchView> xePageInfo;
        PageHelper.startPage(form.getPageNum(), form.getPageSize(), true);
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setIsCheckList(2);
        form.setPurchStatus(VenPurchStatusEnum.CHECKING.getValue());
        try {
            // 3、输出结果
            List<XeVenPurchView> purchList = xeVenPurchService.queryPurchList(form);
            //log.info("查询采购单列表结果：",JSONArray.toJSON(purchList).toString());
            xePageInfo = new XePageInfo<XeVenPurchView>(purchList);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("purchList", purchList);
            map.put("xePageInfo", xePageInfo);
            return sendAjaxOK(map);
        } catch (Exception e) {
            log.error("查询鲜咨达审核采购单列表queryPurchList()异常：{}", e);
            return sendAjaxError("查询财务鲜咨达审核采购单列表异常");
        } finally {
        }
    }

    /**
     * 鲜咨达审核采购单
     *
     * @author 李书峰
     */
    @RequestMapping("xianCheck")
    @ResponseBody
    public BaseResponse xianCheck(@RequestBody XeVenPurchForm form) {
        log.info("--------------鲜咨达审核采购单start-------------------");
        // 1、验证参数
        boolean parError = true;
        Map<String, Object> resultData = null;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())
                && null != form.getCheckStatus()
                && null != form.getPurchStatus()
                && null != form.getCheckStatusPre()
                && null != form.getPurchStatusPre()
                && VenPurchCheckEnum.XIAN_CHECK.getValue().equals(form.getCheckStatusPre())
                && VenPurchCheckEnum.FINANCE_CHECK.getValue().equals(form.getCheckStatus())
                && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())
                && null != form.getVersion()) {
            parError = false;
        }

        if (parError) {
            if (!VenPurchCheckEnum.XIAN_CHECK.getValue().equals(form.getCheckStatusPre())
                    || !VenPurchCheckEnum.XIAN_REJECT.getValue().equals(form.getCheckStatus())
                    || !VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                    || !VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())) {
                resultData = new HashMap<String, Object>();
                resultData.put("code", "1110");
                resultData.put("msg", "单据状态已变更，不能进行该操作");
                return sendAjaxOK(resultData);
            } else {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setModifyUser(userInfo.getLoginName());
        try {
            // 3、输出结果
            List<XeVenPurchForm> xeVenPurchFormList = new ArrayList<XeVenPurchForm>();
            xeVenPurchFormList.add(form);
            String operateContent = "审核通过采购单，单号为：" + form.getPurchOrder();
            Map<String, Object> reult = xeVenPurchService.xianCheck(xeVenPurchFormList);
            int resultSize = Integer.valueOf(reult.get("successSize").toString());
            if (resultSize > 0) {
                insertMqLog(ErpLogTypeEnum.erpPurchXianCheck.getValue(), form.getPurchOrder(), operateContent);
                return sendAjaxOK();
            } else {
                return sendAjaxOK("该采购单不存在，或已发生变更，请刷新页面重试！");
            }
        } catch (Exception e) {
            log.error("鲜咨达审核采购单financeCheck()异常：{}", e);
            return sendAjaxError("鲜咨达审核采购单异常");
        } finally {
            log.info("--------------鲜咨达审核采购单end-------------------");
        }
    }

    /**
     * 批量财务部审核采购单
     *
     * @author 李书峰
     */
    @RequestMapping("financeCheckBatch")
    @ResponseBody
    public BaseResponse financeCheckBatch(@RequestBody XeVenPurchForm formPurch) {
        log.info("--------------财务审核采购单start-------------------");
        // 1、验证参数
        List<XeVenPurchForm> formList = formPurch.getFormList();
        boolean parError = true;
        if (null != formList
                && formList.size() > 0) {
            for (XeVenPurchForm form : formList) {
                if (null != form
                        && StringUtils.isNotBlank(form.getPurchOrder())
                        && null != form.getCheckStatus()
                        && null != form.getPurchStatus()
                        && null != form.getCheckStatusPre()
                        && null != form.getPurchStatusPre()
                        && VenPurchCheckEnum.FINANCE_CHECK.getValue().equals(form.getCheckStatusPre())
                        && VenPurchCheckEnum.CHECKED.getValue().equals(form.getCheckStatus())
                        && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                        && VenPurchStatusEnum.PURCHING.getValue().equals(form.getPurchStatus())
                        && null != form.getVersion()) {
                    parError = false;
                } else {
                    parError = true;
                    break;
                }
            }
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        String userCode = userInfo.getUserCode();
        String loginName = userInfo.getLoginName();
        StringBuilder sbuilder = new StringBuilder("财务部批量审核采购单，单号为：");
        for (XeVenPurchForm form : formList) {
            form.setUserCode(userCode);
            form.setModifyUser(loginName);
            sbuilder.append(form.getPurchOrder()).append(",");
        }
        try {
            // 3、输出结果
            Map<String, Object> reult = xeVenPurchService.financeCheck(formList);
            int resultSize = Integer.valueOf(reult.get("successSize").toString());
            int failSize = Integer.valueOf(reult.get("failSize").toString());
            int totalSize = Integer.valueOf(reult.get("totalSize").toString());
            String msg = reult.get("msg").toString();
            if (resultSize > 0 && resultSize == totalSize) {
                insertMqLog(ErpLogTypeEnum.erpPurchFinanceCheckBatch.getValue(), null, sbuilder.toString());
                return sendAjaxOK();
            } else if (resultSize > 0 && resultSize < totalSize) {
                msg = "批量审核采购单成功" + resultSize + "条，失败" + failSize + "条，审核" + msg;
                reult.put("msg", msg);
                sbuilder.append(msg);
                insertMqLog(ErpLogTypeEnum.erpPurchFinanceCheckBatch.getValue(), null, sbuilder.toString());
                return sendAjaxOK(reult);
            } else {
                msg = "采购单不存在，或已发生变更，请刷新页面重试！";
                reult.put("msg", msg);
                return sendAjaxOK(reult);
            }
        } catch (Exception e) {
            log.error("批量财务审核采购单financeCheckBatch()异常：{}", e);
            return sendAjaxError("批量财务审核采购单异常");
        } finally {
            log.info("--------------财务审核采购单end-------------------");
        }
    }

    /**
     * 批量财务部驳回采购单
     *
     * @author 李书峰
     */
    @RequestMapping("financeRejectBatch")
    @ResponseBody
    public BaseResponse financeRejectBatch(@RequestBody XeVenPurchForm formPurch) {
        log.info("--------------财务审核采购单start-------------------");
        // 1、验证参数
        List<XeVenPurchForm> formList = formPurch.getFormList();
        StringBuilder sbuilder = new StringBuilder("财务部批量驳回采购单，单号为：");
        boolean parError = true;
        if (null != formList
                && formList.size() > 0) {
            //获取用户登录信息
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            String userCode = userInfo.getUserCode();
            String loginName = userInfo.getLoginName();
            for (XeVenPurchForm form : formList) {
                if (null != form
                        && StringUtils.isNotBlank(form.getPurchOrder())
                        && StringUtils.isNotBlank(form.getFinanceExamineRemark())
                        && null != form.getCheckStatus()
                        && null != form.getPurchStatus()
                        && null != form.getCheckStatusPre()
                        && null != form.getPurchStatusPre()
                        && VenPurchCheckEnum.FINANCE_CHECK.getValue().equals(form.getCheckStatusPre())
                        && VenPurchCheckEnum.FINANCE_REJECT.getValue().equals(form.getCheckStatus())
                        && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                        && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())
                        && null != form.getVersion()) {
                    form.setUserCode(userCode);
                    form.setModifyUser(loginName);
                    sbuilder.append(form.getPurchOrder()).append(",");
                    parError = false;
                } else {
                    parError = true;
                    break;
                }
            }
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        try {
            // 3、输出结果
            Map<String, Object> reult = xeVenPurchService.financeCheck(formList);
//			log.info("财务审核采购单结果：",result);
            int resultSize = Integer.valueOf(reult.get("successSize").toString());
            int failSize = Integer.valueOf(reult.get("failSize").toString());
            int totalSize = Integer.valueOf(reult.get("totalSize").toString());
            String msg = reult.get("msg").toString();
            if (resultSize > 0 && resultSize == totalSize) {
                insertMqLog(ErpLogTypeEnum.erpPurchFinanceRejectBatch.getValue(), null, sbuilder.toString());
                return sendAjaxOK();
            } else if (resultSize > 0 && resultSize < totalSize) {
                msg = "批量驳回采购单成功" + resultSize + "条，失败" + failSize + "条，驳回" + msg;
                reult.put("msg", msg);
                sbuilder.append(msg).append("，驳回原因：").append(formPurch.getFinanceExamineRemark());
                insertMqLog(ErpLogTypeEnum.erpPurchFinanceRejectBatch.getValue(), null, sbuilder.toString());
                return sendAjaxOK(reult);
            } else {
                msg = "采购单不存在，或已发生变更，请刷新页面重试！";
                reult.put("msg", msg);
                return sendAjaxOK(reult);
            }
        } catch (Exception e) {
            log.error("批量财务审核采购单financeRejectBatch()异常：{}", e);
            return sendAjaxError("批量财务审核采购单异常");
        } finally {
            log.info("--------------财务审核采购单end-------------------");
        }
    }

    /**
     * 确认收货入库
     *
     * @author 李书峰
     */
    @RequestMapping("goodsReceipt")
    @ResponseBody
    public BaseResponse goodsReceipt(@RequestBody XeVenPurchForm form) {
        // 1、验证参数
        boolean parError = true;
        StringBuilder sBuilder = new StringBuilder("对采购单【");
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())
                && null != form.getPurchStatusPre()
                && VenPurchStatusEnum.PURCHING.getValue().equals(form.getPurchStatusPre())
                && null != form.getPurchType()
                && VenPurchTypeEnum.LARGE_BUY.getValue().equals(form.getPurchType())
                && null != form.getPurchProductList()
                && form.getPurchProductList().size() > 0
                && null != form.getVersion()) {
            sBuilder.append(form.getPurchOrder()).append("】采购收货入库,");
            for (XeVenPurchProductForm proForm : form.getPurchProductList()) {
                if (null == proForm.getCurArriveNum()
                        || StringUtils.isBlank(proForm.getProSku())) {
                    return sendAjaxError("请核对商品和已收货商品数量数据是否全部正确！");
                }
                sBuilder.append("商品sku：【").append(proForm.getProSku()).append("】的入库数量为：【").append(proForm.getCurArriveNum()).append("】，");
            }
            parError = false;
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setModifyUser(userInfo.getLoginName());

        try {
            // 3、输出结果
            int result = xeVenPurchService.updateGoodsReceipt(form);
            //log.info("编辑采购单结果：",result);
            if (result > 0 && result < 11) {
                insertMqLog(ErpLogTypeEnum.erpPurchGoodsReceipt.getValue(), form.getPurchOrder(), sBuilder.toString());
                return sendAjaxOK();
            } else if (result == 200) {
                return sendAjaxOK("只有采购中的集采采购单可以采购收货入库！ ");
            } else if (result == 300) {
                return sendAjaxOK("该采购单已收货入库完成，请问重复操作！ ");
            } else {
                return sendAjaxOK("采购收货入库异常！ ");
            }
        } catch (Exception e) {
            log.error("收货入库goodsReceipt()异常：{}", e);
            return sendAjaxError("收货入库异常");
        } finally {
        }
    }

    /**
     * 批量删除采购单
     *
     * @author 李书峰
     */
    @RequestMapping("delBatchPurch")
    @ResponseBody
    public BaseResponse delBatchPurch(@RequestBody XeVenPurchForm formPurch) {
        log.info("--------------批量删除采购单start-------------------");
        // 1、验证参数
        List<XeVenPurchForm> formList = formPurch.getFormList();
        boolean parError = true;
        if (null != formList
                && formList.size() > 0) {
            for (XeVenPurchForm form : formList) {
                if (null != form
                        && StringUtils.isNotBlank(form.getPurchOrder())
                        && null != form.getPurchStatusPre()
                        && VenPurchStatusEnum.WAIT_SUBMIT.getValue().equals(form.getPurchStatusPre())
                        && null != form.getCheckStatusPre()
                        && VenPurchCheckEnum.WAIT_SUBMIT.getValue().equals(form.getCheckStatusPre())
                        && null != form.getPurchType()
                        && VenPurchTypeEnum.LARGE_BUY.getValue().equals(form.getPurchType())
                        && null != form.getVersion()) {
                    parError = false;
                } else {
                    parError = true;
                    break;
                }
            }
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        String userCode = userInfo.getUserCode();
        String loginName = userInfo.getLoginName();
        StringBuilder sbuilder = new StringBuilder("批量删除采购单，单号为：");
        for (XeVenPurchForm form : formList) {
            form.setUserCode(userCode);
            form.setModifyUser(loginName);
            sbuilder.append(form.getPurchOrder()).append(",");
        }
        try {
            // 3、输出结果
            Map<String, Object> reult = xeVenPurchService.deletePurchOrder(formList);

            int resultSize = Integer.valueOf(reult.get("successSize").toString());
            int failSize = Integer.valueOf(reult.get("failSize").toString());
            int totalSize = Integer.valueOf(reult.get("totalSize").toString());
            String msg = reult.get("msg").toString();
            if (resultSize > 0 && resultSize == totalSize) {
                insertMqLog(ErpLogTypeEnum.erpPurchDelBatchPurch.getValue(), null, sbuilder.toString());
                return sendAjaxOK();
            } else if (resultSize > 0 && resultSize < totalSize) {
                msg = "批量删除采购单成功" + resultSize + "条，失败" + failSize + "条，删除" + msg;
                reult.put("msg", msg);
                sbuilder.append(msg);
                insertMqLog(ErpLogTypeEnum.erpPurchDelBatchPurch.getValue(), null, sbuilder.toString());
                return sendAjaxOK(reult);
            } else {
                msg = "采购单不存在，或已发生变更，请刷新页面重试！";
                reult.put("msg", msg);
                return sendAjaxOK(reult);
            }
        } catch (Exception e) {
            log.error("批量删除采购单delBatchPurch()异常：{}", e);
            return sendAjaxError("批量删除采购单异常");
        } finally {
            log.info("--------------批量删除采购单end-------------------");
        }
    }

    /**
     * 批量采购部审核采购单
     *
     * @author 李书峰
     */
    @RequestMapping("purchCheckBatch")
    @ResponseBody
    public BaseResponse purchCheckBatch(@RequestBody XeVenPurchForm formPurch) {
        log.info("--------------采购审核采购单start-------------------");
        // 1、验证参数
        List<XeVenPurchForm> formList = formPurch.getFormList();
        boolean parError = true;
        if (null != formList
                && formList.size() > 0) {
            for (XeVenPurchForm form : formList) {
                if (null != form
                        && StringUtils.isNotBlank(form.getPurchOrder())
                        && null != form.getCheckStatus()
                        && null != form.getPurchStatus()
                        && null != form.getCheckStatusPre()
                        && null != form.getPurchStatusPre()
                        && (VenPurchCheckEnum.PURCH_CHECK.getValue().equals(form.getCheckStatusPre())
                        || VenPurchCheckEnum.FINANCE_REJECT.getValue().equals(form.getCheckStatusPre())
                        || VenPurchCheckEnum.XIAN_REJECT.getValue().equals(form.getCheckStatusPre())
                        || VenPurchCheckEnum.PURCH_REJECT.getValue().equals(form.getCheckStatusPre()))
                        && VenPurchCheckEnum.XIAN_CHECK.getValue().equals(form.getCheckStatus())
                        && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                        && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())
                        && null != form.getVersion()) {
                    parError = false;
                } else {
                    parError = true;
                    break;
                }
            }
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        String userCode = userInfo.getUserCode();
        String loginName = userInfo.getLoginName();
        StringBuilder sbuilder = new StringBuilder("采购部批量审核采购单，单号为：");
        for (XeVenPurchForm form : formList) {
            form.setUserCode(userCode);
            form.setModifyUser(loginName);
            sbuilder.append(form.getPurchOrder()).append(",");
        }
        try {
            // 3、输出结果
            Map<String, Object> reult = xeVenPurchService.purchCheck(formList);
            int resultSize = Integer.valueOf(reult.get("successSize").toString());
            int failSize = Integer.valueOf(reult.get("failSize").toString());
            int totalSize = Integer.valueOf(reult.get("totalSize").toString());
            String msg = reult.get("msg").toString();
            if (resultSize > 0 && resultSize == totalSize) {
                insertMqLog(ErpLogTypeEnum.erpPurchPurchCheckBatch.getValue(), null, sbuilder.toString());
                return sendAjaxOK();
            } else if (resultSize > 0 && resultSize < totalSize) {
                msg = "批量审核采购单成功" + resultSize + "条，失败" + failSize + "条，审核" + msg;
                reult.put("msg", msg);
                sbuilder.append(msg);
                insertMqLog(ErpLogTypeEnum.erpPurchPurchCheckBatch.getValue(), "", sbuilder.toString());
                return sendAjaxOK(reult);
            } else {
                msg = "采购单不存在，或已发生变更，请刷新页面重试！";
                reult.put("msg", msg);
                return sendAjaxOK(reult);
            }
        } catch (Exception e) {
            log.error("批量采购审核采购单purchCheckBatch()异常：{}", e);
            return sendAjaxError("批量采购审核采购单异常");
        } finally {
            log.info("--------------采购审核采购单end-------------------");
        }
    }

    /**
     * 批量采购部驳回采购单
     *
     * @author 李书峰
     */
    @RequestMapping("purchRejectBatch")
    @ResponseBody
    public BaseResponse purchRejectBatch(@RequestBody XeVenPurchForm formPurch) {
        log.info("--------------采购审核采购单start-------------------");
        // 1、验证参数
        List<XeVenPurchForm> formList = formPurch.getFormList();
        boolean parError = true;
        if (null != formList
                && formList.size() > 0) {
            for (XeVenPurchForm form : formList) {
                if (null != form
                        && StringUtils.isNotBlank(form.getPurchOrder())
                        && StringUtils.isNotBlank(form.getPurchExamineRemark())
                        && null != form.getCheckStatus()
                        && null != form.getPurchStatus()
                        && null != form.getCheckStatusPre()
                        && null != form.getPurchStatusPre()
                        && VenPurchCheckEnum.PURCH_CHECK.getValue().equals(form.getCheckStatusPre())
                        && VenPurchCheckEnum.PURCH_REJECT.getValue().equals(form.getCheckStatus())
                        && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                        && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())
                        && null != form.getVersion()) {
                    parError = false;
                } else {
                    parError = true;
                    break;
                }
            }
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        String userCode = userInfo.getUserCode();
        String loginName = userInfo.getLoginName();
        StringBuilder sbuilder = new StringBuilder("采购部批量驳回采购单，单号为：");
        for (XeVenPurchForm form : formList) {
            form.setUserCode(userCode);
            form.setModifyUser(loginName);
            sbuilder.append(form.getPurchOrder()).append(",");
        }
        try {
            // 3、输出结果
            Map<String, Object> reult = xeVenPurchService.purchCheck(formList);
            int resultSize = Integer.valueOf(reult.get("successSize").toString());
            int failSize = Integer.valueOf(reult.get("failSize").toString());
            int totalSize = Integer.valueOf(reult.get("totalSize").toString());
            String msg = reult.get("msg").toString();
            if (resultSize > 0 && resultSize == totalSize) {
                insertMqLog(ErpLogTypeEnum.erpPurchPurchRejectBatch.getValue(), null, sbuilder.toString());
                return sendAjaxOK();
            } else if (resultSize > 0 && resultSize < totalSize) {
                msg = "批量驳回采购单成功" + resultSize + "条，失败" + failSize + "条，驳回" + msg;
                reult.put("msg", msg);
                sbuilder.append(msg).append("，驳回原因：").append(formPurch.getPurchExamineRemark());
                insertMqLog(ErpLogTypeEnum.erpPurchPurchRejectBatch.getValue(), "", sbuilder.toString());
                return sendAjaxOK(reult);
            } else {
                msg = "采购单不存在，或已发生变更，请刷新页面重试！";
                reult.put("msg", msg);
                return sendAjaxOK(reult);
            }
        } catch (Exception e) {
            log.error("批量采购审核采购单purchRejectBatch()异常：{}", e);
            return sendAjaxError("批量采购审核采购单异常");
        } finally {
            log.info("--------------采购审核采购单end-------------------");
        }
    }

    /**
     * 鲜咨达批量审核采购单
     *
     * @author 李书峰
     */
    @RequestMapping("xianCheckBatch")
    @ResponseBody
    public BaseResponse xianCheckBatch(@RequestBody XeVenPurchForm formPurch) {
        log.info("--------------鲜咨达批量审核采购单start-------------------");
        // 1、验证参数
        List<XeVenPurchForm> formList = formPurch.getFormList();
        boolean parError = true;
        if (null != formList
                && formList.size() > 0) {
            for (XeVenPurchForm form : formList) {
                if (null != form
                        && StringUtils.isNotBlank(form.getPurchOrder())
                        && null != form.getCheckStatus()
                        && null != form.getPurchStatus()
                        && null != form.getCheckStatusPre()
                        && null != form.getPurchStatusPre()
                        && VenPurchCheckEnum.XIAN_CHECK.getValue().equals(form.getCheckStatusPre())
                        && VenPurchCheckEnum.FINANCE_CHECK.getValue().equals(form.getCheckStatus())
                        && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                        && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())
                        && null != form.getVersion()) {
                    parError = false;
                } else {
                    parError = true;
                    break;
                }
            }
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        String userCode = userInfo.getUserCode();
        String loginName = userInfo.getLoginName();
        StringBuilder sbuilder = new StringBuilder("鲜咨达批量审核采购单，单号为：");
        for (XeVenPurchForm form : formList) {
            form.setUserCode(userCode);
            form.setModifyUser(loginName);
            sbuilder.append(form.getPurchOrder()).append(",");
        }
        try {
            // 3、输出结果
            Map<String, Object> reult = xeVenPurchService.xianCheck(formList);
            int resultSize = Integer.valueOf(reult.get("successSize").toString());
            int failSize = Integer.valueOf(reult.get("failSize").toString());
            int totalSize = Integer.valueOf(reult.get("totalSize").toString());
            String msg = reult.get("msg").toString();
            if (resultSize > 0 && resultSize == totalSize) {
                insertMqLog(ErpLogTypeEnum.erpPurchXianCheckBatch.getValue(), null, sbuilder.toString());
                return sendAjaxOK();
            } else if (resultSize > 0 && resultSize < totalSize) {
                msg = "批量审核采购单成功" + resultSize + "条，失败" + failSize + "条，审核" + msg;
                reult.put("msg", msg);
                sbuilder.append(msg);
                insertMqLog(ErpLogTypeEnum.erpPurchXianCheckBatch.getValue(), null, sbuilder.toString());
                return sendAjaxOK(reult);
            } else {
                msg = "采购单不存在，或已发生变更，请刷新页面重试！";
                reult.put("msg", msg);
                return sendAjaxOK(reult);
            }
        } catch (Exception e) {
            log.error("鲜咨达批量审核采购单financeCheckBatch()异常：{}", e);
            return sendAjaxError("鲜咨达批量审核采购单异常");
        } finally {
            log.info("--------------鲜咨达批量审核采购单end-------------------");
        }
    }

    /**
     * 批量鲜咨达驳回采购单
     *
     * @author 李书峰
     */
    @RequestMapping("xianRejectBatch")
    @ResponseBody
    public BaseResponse xianRejectBatch(@RequestBody XeVenPurchForm formPurch) {
        log.info("--------------鲜咨达驳回采购单start-------------------");
        // 1、验证参数
        List<XeVenPurchForm> formList = formPurch.getFormList();
        StringBuilder sbuilder = new StringBuilder("鲜咨达批量驳回采购单，单号为：");
        boolean parError = true;
        if (null != formList
                && formList.size() > 0) {
            //获取用户登录信息
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            String userCode = userInfo.getUserCode();
            String loginName = userInfo.getLoginName();
            for (XeVenPurchForm form : formList) {
                if (null != form
                        && StringUtils.isNotBlank(form.getPurchOrder())
                        && StringUtils.isNotBlank(form.getXianExamineRemark())
                        && null != form.getCheckStatus()
                        && null != form.getPurchStatus()
                        && null != form.getCheckStatusPre()
                        && null != form.getPurchStatusPre()
                        && VenPurchCheckEnum.XIAN_CHECK.getValue().equals(form.getCheckStatusPre())
                        && VenPurchCheckEnum.XIAN_REJECT.getValue().equals(form.getCheckStatus())
                        && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                        && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())
                        && null != form.getVersion()) {
                    form.setUserCode(userCode);
                    form.setModifyUser(loginName);
                    sbuilder.append(form.getPurchOrder()).append(",");
                    parError = false;
                } else {
                    parError = true;
                    break;
                }
            }
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        try {
            // 3、输出结果
            Map<String, Object> reult = xeVenPurchService.xianCheck(formList);
//			log.info("财务审核采购单结果：",result);
            int resultSize = Integer.valueOf(reult.get("successSize").toString());
            int failSize = Integer.valueOf(reult.get("failSize").toString());
            int totalSize = Integer.valueOf(reult.get("totalSize").toString());
            String msg = reult.get("msg").toString();
            if (resultSize > 0 && resultSize == totalSize) {
                insertMqLog(ErpLogTypeEnum.erpPurchXianRejectBatch.getValue(), null, sbuilder.toString());
                return sendAjaxOK();
            } else if (resultSize > 0 && resultSize < totalSize) {
                msg = "批量驳回采购单成功" + resultSize + "条，失败" + failSize + "条，驳回" + msg;
                reult.put("msg", msg);
                sbuilder.append(msg).append("，驳回原因：").append(formPurch.getFinanceExamineRemark());
                insertMqLog(ErpLogTypeEnum.erpPurchXianRejectBatch.getValue(), null, sbuilder.toString());
                return sendAjaxOK(reult);
            } else {
                msg = "采购单不存在，或已发生变更，请刷新页面重试！";
                reult.put("msg", msg);
                return sendAjaxOK(reult);
            }
        } catch (Exception e) {
            log.error("鲜咨达批量驳回采购单financeRejectBatch()异常：{}", e);
            return sendAjaxError("鲜咨达批量驳回采购单异常");
        } finally {
            log.info("--------------鲜咨达批量驳回采购单end-------------------");
        }
    }

    /**
     * 鲜咨达驳回采购单
     *
     * @author 李书峰
     */
    @RequestMapping("xianReject")
    @ResponseBody
    public BaseResponse xianReject(@RequestBody XeVenPurchForm form) {
        log.info("--------------鲜咨达驳回采购单start-------------------");
        // 1、验证参数
        boolean parError = true;
        Map<String, Object> resultData = null;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())
                && StringUtils.isNotBlank(form.getXianExamineRemark())
                && null != form.getCheckStatus()
                && null != form.getPurchStatus()
                && null != form.getCheckStatusPre()
                && null != form.getPurchStatusPre()
                && VenPurchCheckEnum.XIAN_CHECK.getValue().equals(form.getCheckStatusPre())
                && VenPurchCheckEnum.XIAN_REJECT.getValue().equals(form.getCheckStatus())
                && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                && VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())
                && null != form.getVersion()) {
            parError = false;
        }
        if (parError) {
            if (!VenPurchCheckEnum.XIAN_CHECK.getValue().equals(form.getCheckStatusPre())
                    || !VenPurchCheckEnum.XIAN_REJECT.getValue().equals(form.getCheckStatus())
                    || !VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatusPre())
                    || !VenPurchStatusEnum.CHECKING.getValue().equals(form.getPurchStatus())) {
                resultData = new HashMap<String, Object>();
                resultData.put("code", "1110");
                resultData.put("msg", "单据状态已变更，不能进行该操作");
                return sendAjaxOK(resultData);
            } else {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setModifyUser(userInfo.getLoginName());
        try {
            // 3、输出结果
            List<XeVenPurchForm> xeVenPurchFormList = new ArrayList<XeVenPurchForm>();
            xeVenPurchFormList.add(form);
            String operateContent = "鲜咨达审核驳回采购单，单号为：" + form.getPurchOrder() + "，驳回原因：" + form.getFinanceExamineRemark();
            Map<String, Object> reult = xeVenPurchService.xianCheck(xeVenPurchFormList);
            int resultSize = Integer.valueOf(reult.get("successSize").toString());
            if (resultSize > 0) {
                insertMqLog(ErpLogTypeEnum.erpPurchXianReject.getValue(), form.getPurchOrder(), operateContent);
                return sendAjaxOK();
            } else {
                return sendAjaxOK("该采购单不存在，或已发生变更，请刷新页面重试！");
            }
        } catch (Exception e) {
            log.error("鲜咨达审核采购单financeCheck()异常：{}", e);
            return sendAjaxError("鲜咨达审核采购单异常");
        } finally {
            log.info("--------------鲜咨达审核采购单end-------------------");
        }
    }

    /**
     * 采购收货入库详情
     *
     * @author 李书峰
     */
    @RequestMapping("detailPurch")
    @ResponseBody
    public BaseResponse detailPurch(@RequestBody XeVenPurchForm form) {
        log.info("--------------查询采购详情start-------------------");
        Map<String, Object> resultMap = new HashMap<String, Object>();
        // 1、验证参数
        boolean parError = true;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())
                && null != form.getVersion()) {
            parError = false;
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        try {
            // 3、输出结果
            XeVenPurchView purch = xeVenPurchService.queryPurchDetail(form);
            //log.info("查询采购详情结果：",JSONObject.toJSON(purch).toString());
            if (null == purch || StringUtils.isBlank(purch.getPurchOrder())) {
                resultMap.put("code", "1110");
                resultMap.put("msg", "单据状态已变更，不能进行该操作");
            } else {
                resultMap.put("purch", purch);
                String picServer = paramConfig.getImgUrl();//图片服务器地址
                resultMap.put("picServer", picServer);
                resultMap.put("picDir", picDir);
            }
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("查询采购详情queryPurchDetail()异常：{}", e);
            return sendAjaxError("查询采购详情异常");
        } finally {
            log.info("--------------查询采购详情end-------------------");
        }

    }

    /**
     * 财务部采购单详情
     *
     * @author 李书峰
     */
    @RequestMapping("detailPurchFinance")
    @ResponseBody
    public BaseResponse detailPurchFinance(@RequestBody XeVenPurchForm form) {
        log.info("--------------查询采购详情start-------------------");
        Map<String, Object> resultMap = new HashMap<String, Object>();
        // 1、验证参数
        boolean parError = true;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())
                && null != form.getVersion()) {
            parError = false;
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        try {
            // 3、输出结果
            XeVenPurchView purch = xeVenPurchService.queryPurchDetail(form);
            //log.info("查询采购详情结果：",JSONObject.toJSON(purch).toString());
            if (null == purch || StringUtils.isBlank(purch.getPurchOrder())) {
                resultMap.put("code", "1110");
                resultMap.put("msg", "单据状态已变更，不能进行该操作");
            } else {
                resultMap.put("purch", purch);
                String picServer = paramConfig.getImgUrl();//图片服务器地址
                resultMap.put("picServer", picServer);
                resultMap.put("picDir", picDir);
            }
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("查询采购详情queryPurchDetail()异常：{}", e);
            return sendAjaxError("查询采购详情异常");
        } finally {
            log.info("--------------查询采购详情end-------------------");
        }

    }

    /**
     * 鲜咨达采购单详情
     *
     * @author 李书峰
     */
    @RequestMapping("detailPurchXian")
    @ResponseBody
    public BaseResponse detailPurchXian(@RequestBody XeVenPurchForm form) {
        log.info("--------------查询采购详情start-------------------");
        Map<String, Object> resultMap = new HashMap<String, Object>();
        // 1、验证参数
        boolean parError = true;
        if (null != form
                && StringUtils.isNotBlank(form.getPurchOrder())
                && null != form.getVersion()) {
            parError = false;
        }
        if (parError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        try {
            // 3、输出结果
            XeVenPurchView purch = xeVenPurchService.queryPurchDetail(form);
            //log.info("查询采购详情结果：",JSONObject.toJSON(purch).toString());
            if (null == purch || StringUtils.isBlank(purch.getPurchOrder())) {
                resultMap.put("code", "1110");
                resultMap.put("msg", "单据状态已变更，不能进行该操作");
            } else {
                resultMap.put("purch", purch);
                String picServer = paramConfig.getImgUrl();//图片服务器地址
                resultMap.put("picServer", picServer);
                resultMap.put("picDir", picDir);
            }
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("查询采购详情queryPurchDetail()异常：{}", e);
            return sendAjaxError("查询采购详情异常");
        } finally {
            log.info("--------------查询采购详情end-------------------");
        }

    }

    /**
     * 订单汇总采购 采购单查询
     */
    @RequestMapping("querySummaryPurch")
    @ResponseBody
    public BaseResponse querySummaryPurch(@RequestBody XeVenPurchForm form) {
        if (null == form || StringUtils.isBlank(form.getStoreId()) || null == form.getSkuList() || form.getSkuList().size() == 0) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        log.info("订单汇总采购查询入参：{}", JSON.toJSONString(form));
        try {
            if (null != form.getSearchTypeQuery()) {
                switch (form.getSearchTypeQuery()) {
                    case 1:
                        break;
                    case 2:
                        form.setProName(form.getPurchOrder());
                        form.setPurchOrder(null);
                        break;
                    case 3:
                        form.setProNum(form.getPurchOrder());
                        form.setPurchOrder(null);
                        break;
                    case 4:
                        form.setSupplierName(form.getPurchOrder());
                        form.setPurchOrder(null);
                        break;
                    default:
                        break;
                }
            }
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
			/*ErpUserInfo userInfo = new ErpUserInfo();
			userInfo.setUserCode("SH1709228481165");*/
            form.setUserCode(userInfo.getUserCode());
            XePageInfo<XeVenSumPurchView> xePageInfo;
            PageHelper.startPage(form.getPageNum(), form.getPageSize(), true);
            List<XeVenSumPurchView> actionList = this.xeVenPurchService.querySummaryPurch(form);
            xePageInfo = new XePageInfo<XeVenSumPurchView>(actionList);
            Map<String, Object> resultMap = new HashMap<String, Object>();
            resultMap.put("actionList", actionList);
            resultMap.put("xePageInfo", xePageInfo);
            String picServer = paramConfig.getImgUrl();//图片服务器地址
            resultMap.put("picServer", picServer);
            resultMap.put("picDir", picDir);
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.info("订单汇总采购查询异常：{}", e);
            return sendAjaxError();
        }
    }

    private void insertMqLog(String logType, String key, String operatorContent) {
        try {
            String ipAddress = RequestUtil.getClientIpAddress(request);
            if (StringUtils.isBlank(logType)) {
                logType = ErpLogTypeEnum.erpStorage.getValue();
            }
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            String userCode = userInfo.getUserCode();
            OpertorLogUtil.opertorLog.sendOperatorLogByParam(ipAddress, key, logType, userInfo.getUserName(), operatorContent, userCode);
        } catch (Exception e) {
            log.error("采购单MQ日志插入失败,logType={},operatorContent={}", logType, operatorContent);
        }
    }

    /**
     * 财务部取消审核
     *
     * @author 李书峰
     */
    @RequestMapping("/cancelFinanceCheck")
    @ResponseBody
    public BaseResponse cancelFinanceCheck(@RequestBody XeVenPurchForm form) {
        log.info("-------form---->>" + JSON.toJSONString(form));
        // 1、验证参数
        if (StringUtils.isEmpty(form.getPurchOrder())) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        // 2、拼装参数
        //获取用户登录信息
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        form.setUserCode(userInfo.getUserCode());
        form.setModifyUser(userInfo.getLoginName());
        try {
            // 3、输出结果
            int reult = xeVenPurchService.cancelFinanceCheck(form);
            if (reult > 0) {
                return sendAjaxOK();
            } else {
                return sendAjaxOK("取消审核失败！");
            }
        } catch (Exception e) {
            log.error("cancelFinanceCheck()--取消审核失败！：{}", e);
            return sendAjaxError("取消审核失败！");
        }
    }
}
  
